package cn.smartorigin.soas.frame.panel;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JPanel;

public class CellClientMainPagePanel extends CellPagePanel implements PortletPanel{
	
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int clientId;
	
	private boolean isFullScreen = false;
    private GridLayout layout = new GridLayout(1, 3);
    private List<Portlet> chartList = new ArrayList<Portlet>();
    private JPanel layoutPanel = new JPanel();
    
	private OrderPage op;
	private ProductListPage plp;
	private AnalysisPage ap;
	
    public CellClientMainPagePanel(int id) {
		super();
		this.clientId = id;
        layout.setHgap(3);
        layout.setVgap(3);   
        
        op = new OrderPage(clientId);
        plp = new ProductListPage(clientId);
        ap = new AnalysisPage(clientId);
        
        chartList.add(plp);
        chartList.add(op);
        chartList.add(ap);
        
        BtnActionListener bal = new BtnActionListener();
        int size = chartList.size();
        for (int i = 0; i < size; i++) {
        	chartList.get(i).getImageButton().addActionListener(bal);
        }
        initialize();
	}
    
    public void initialize() {
    	layoutPanel.setLayout(layout);
    	for (int i = 0; i < chartList.size(); i++) {
            //this.add((Portlet) chartList.get(i));
    		layoutPanel.add((Portlet) chartList.get(i));
        }
    	this.add(layoutPanel);
    }
    
//	private JPanel initPanel(){
//		BtnMouseListener bml = new BtnMouseListener();
//		btn1.addMouseListener(bml);
//		btn2.addMouseListener(bml);
//		btn3.addMouseListener(bml);
//		//jp.setBackground(Color.white);
//		
//		return jp;
//	}

	@Override
	public void fullScreen(Portlet portlet) {
		// TODO Auto-generated method stub
        this.removeAll();
        isFullScreen = !isFullScreen;
        portlet.showMode(isFullScreen);
        if (isFullScreen) {
            //this.setLayout(new BorderLayout());
            //this.add(portlet, BorderLayout.CENTER);
        	layoutPanel.removeAll();
        	layoutPanel.setLayout(new BorderLayout());
        	layoutPanel.add(portlet, BorderLayout.CENTER);
        	this.add(layoutPanel);
        } else {
        	layoutPanel.removeAll();
        	initialize();
        }
        this.repaint();
        this.revalidate();
	}
	
	class BtnActionListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			Object obj = e.getSource();
			if(obj == plp.getImageButton()){
				fullScreen(plp);
			}else if(obj == op.getImageButton()){
				fullScreen(op);
			}else if(obj == ap.getImageButton()){
				fullScreen(ap);
			}
		}
		
	}
	
}
	
